package org.window.leeCode0003;

public class Solution {

    public static void main(String[] args) {

        String str="pwwkew";

        System.out.println("=========="+str.length()+"==========");

        Solution solution=new Solution();
        System.out.println(solution.lengthOfLongestSubstring(str));;

    }

    public int lengthOfLongestSubstring(String s) {

        int l=0,r=0,max=0;
        String s1=null;
        int[] nums=new int[128];
        StringBuilder res=new StringBuilder();

        while(r<s.length()){
            char c=s.charAt(r++);
            if (nums[c]==0){
                nums[c]++;
                res.append(c);
                max=Math.max(max,res.length());
                s1=res.toString();
            }else{
                nums[c]++;
                while(nums[c]>=2){
                    if (res.charAt(0)!=c){
                        nums[res.charAt(0)]--;
                        res.deleteCharAt(0);
                    }else{
                        nums[c]--;
                        res.deleteCharAt(0);
                    }
                }
                res.append(c);
            }
        }
        System.out.println(res.toString());
        System.out.println(s1);
        return max;

    }

}
